<?php
require "$sysroot/lib/3rdparty/jsmin.php";

class TdJavascript extends TdComponent {
  var $name;
  var $value;
  var $minify = false;
  var $js = array();


  function __construct($id, $template="") {
    parent::__construct($id, $template);
  }

  function addJS($js_file) {
    $this->js[] = $js_file;
  }

  function __toString() {
    header('Content-type: text/javascript');
    ob_start();
    foreach ($this->js as $script) {
      if (is_file($script)) {
        include($script);
      }
    }

    if ($this->minify) {
      return JSMin::minify(ob_get_clean());
    }
    else {
      return ob_get_clean();
    }
  }

  function setMinify($value) {
    $this->minify = $value;
  }

  function getMinify() {
    return $this->minify;
  }
}

?>
